<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>请假审批</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
</head>
<body>
<form class="layui-form" >
    <div class="mainBox">
        <div class="main-container">
            <div class="main- container">
                <div class="layui-form-item">
                    <label class="layui-form-label">学号</label>
                    <div class="layui-input-block">
                        <div id="userId" class="layui-form-mid layui-word-aux">学号</div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <div id="realName" class="layui-form-mid layui-word-aux">姓名</div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">开始时间</label>
                    <div class="layui-input-block">
                        <div id="startTime" class="layui-form-mid layui-word-aux">请假开始时间</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">结束时间</label>
                    <div class="layui-input-block">
                        <div id="endTime" class="layui-form-mid layui-word-aux">请假结束时间</div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">请假原因</label>
                    <div class="layui-input-block">
                        <div id="leaveReason" class="layui-form-mid layui-word-aux">请假原因</div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">回复信息</label>
                    <div class="layui-input-block">
                    <textarea id="rejectInfo" name="rejectInfo" required
                              lay-verify="title" placeholder="请假审核回复（选填）"
                              class="layui-textarea" style="height: 160px"></textarea>
                    </div>
                </div>
                <input id="leaveId" type="hidden" name="leaveId">

            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="layui-btn pear-btn-sm" lay-submit=""
                    lay-filter="pass">
                <i class="layui-icon layui-icon-ok"></i>
                通过
            </button>
            <button type="submit" class="layui-btn layui-btn-danger pear-btn-sm"
                    lay-submit="" lay-filter="reject">
                <i class="layui-icon layui-icon-close"></i>
                拒绝
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery','laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;


        form.on('submit(pass)', function (data) {
            console.log(data.field)
            let index = layer.load(2, {time: 10*1000}); //又换了种风格，并且设定最长等待10秒
            $.ajax({
                url: '/StudentLeave/updateInfo',
                data: {
                    rejectInfo:data.field.rejectInfo,
                    status:2,
                    leaveId:data.field.leaveId
                },
                dataType: 'json',
                type: 'get',
                success: function (result) {
                    layer.close(index);
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //console.log(parent.layui.jquery(".layui-laypage-em").next().html());
                            parent.layui.table.reload("user-table", {
                                data: result.data,
                                page: {
                                    layout: ['count', 'prev', 'page', 'next', 'skip']
                                    , curr: parent.layui.jquery(".layui-laypage-em").next().html()
                                    , groups: 3
                                    , last: false
                                }
                            });
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

        form.on('submit(reject)', function (data) {
            console.log(data.field);
            let index = layer.load(2, {time: 10*1000}); //又换了种风格，并且设定最长等待10秒
            $.ajax({
                url: '/StudentLeave/updateInfo',
                data: {
                    rejectInfo:data.field.rejectInfo,
                    status:0,
                    leaveId:data.field.leaveId
                },
                dataType: 'json',
                type: 'get',
                success: function (result) {
                    layer.close(index);
                    if (result.success) {
                        layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页
                            //console.log(parent.layui.jquery(".layui-laypage-em").next().html());
                            parent.layui.table.reload("user-table", {
                                data: result.data,
                                page: {
                                    layout: ['count', 'prev', 'page', 'next', 'skip']
                                    , curr: parent.layui.jquery(".layui-laypage-em").next().html()
                                    , groups: 3
                                    , last: false
                                }
                            });
                        });
                    } else {
                        layer.msg(result.msg, {icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
